﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<SLIC.Models.UserAdministration.UserDataModel>>" %>

<%@ Import Namespace="MvcContrib.UI.Pager" %>
<%@ Import Namespace="MvcContrib.Pagination" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    ViewUsers
</asp:Content>
<%--<script src="../../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>--%>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

 <%
        /// <summary>
        /// 
        ///  <title>SLIC</title>
        ///  <description>View Users page for view all users </description>
        ///  <copyRight>Copyright (c) 2011</copyRight>
        ///  <company>IronOne Technologies (Pvt)Ltd</company>
        ///  <createdOn>2011-08-05</createdOn>
        ///  <author></author>
        ///  <modification>
        ///     <modifiedBy></modifiedBy>
        ///      <modifiedDate></modifiedDate>
        ///     <description></description>
        ///  </modification>
        ///
        /// </summary>                                                                                 
    %>


    <%--  <script src="../../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>--%>
    <script type="text/javascript">
        // alert("hi2");
        //alert($(document));
        $(document).ready(function () {
            //alert("hi");  
          //  alert(-1);
            $('#chkHeader').change(function () {
               // alert(0);
                if ($(this).is(':checked')) {
                  //  alert(1);
                    $('.foo').attr('checked', 'checked');
                } else {
                   // alert(2);
                    $('.foo').removeAttr('checked');
                }
            });
        });


        //        function checkMsg() {
        //            alert("123");
        //        }
    </script>
    <h2>
        Users
        <%if (ViewData["roleName"] != null && !String.IsNullOrEmpty(ViewData["roleName"].ToString()))
          { %>
        >
        <%:ViewData["roleName"]%>s
        <%} %>
    </h2>
    <%using (Html.BeginForm("UnlockUsers", "UserAdministration", FormMethod.Post))
      {%>
    <%   ModelState err = ViewContext.ViewData.ModelState["err"];
         SLIC.Controllers.GenException result = null;

         if (err != null)
         {
             result = (SLIC.Controllers.GenException)err.Errors.ElementAt(0).Exception;
    %>
    <%:result.Message%><br />
    <%}
         //else
          if (Model!=null)
         {
             var isAgent = Convert.ToBoolean(ViewData["isAgent"]);
    %>
    <br />
    <table id="grid">
        <tr>
            <%if (ViewData["isLockedUserPage"] != null && Convert.ToBoolean(ViewData["isLockedUserPage"]))
              {%>
            <th style="" width="10px" scope="col">
                <input type="checkbox" id="chkHeader" />
            </th>
            <%} %>
            <%if (isAgent)
              { %>
            <th>
                CSRCode
            </th>
            <%} %>
            <th>
                User Name
            </th>
            <th>
                First Name
            </th>
            <th>
                Last Name
            </th>
             <th>
               Email
            </th>
            <%if (ViewData["isLockedUserPage"] == null || !Convert.ToBoolean(ViewData["isLockedUserPage"]))
              {%>
            <th>
                Actions
            </th>
            <%} %>
        </tr>
        <%bool oddEven = true; %>
        <%int i = 0; %>
        <% foreach (var item in Model)
           { %>
        <%i++; %>
        <tr class="<%= (oddEven = !oddEven) ? "even" : "odd" %>">
            <%--<td class="normaltds" width="30px">
                <%: item.UserId %>
            </td>--%>
            <%if (ViewData["isLockedUserPage"] != null && Convert.ToBoolean(ViewData["isLockedUserPage"]))
              {%>
            <td class="normaltds" style="text-align: center;" width="10px">
                <%-- <%:Html.CheckBox("chkSelected", new { @class = "foo", @value = item.UserId })%>--%>
                <%:Html.CheckBox("chkSelected", new { @class = "foo", @value = item.username })%>
            </td>
            <%} if (isAgent)
              { %>
            <td class="normaltds" width="30px" style="text-align: center;">
                <%: item.CSRCode %>
            </td>
            <%} %>
            <td class="normaltds" width="30px">
                <%: item.username %>
            </td>
            <td class="normaltds" width="30px">
                <%: item.firstName %>
            </td>
            <td class="normaltds" width="30px">
                <%: item.lastname %>
            </td>
              <td class="normaltds" width="30px">
                <%: item.email %>
            </td>
            <%--  <td class="normaltds" width="30px">
                <%: item.isAgent %>
            </td>--%>
            <%if (ViewData["isLockedUserPage"] == null || !Convert.ToBoolean(ViewData["isLockedUserPage"]))
              {%>
            <td class="normaltds" width="60px" style="text-align: left;">
                <%--    <%: Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) %>--%>   
                <div style="padding-left:5px;">
                 <a href="<%= Url.Action("ViewUser", "UserAdministration", new{userId = item.UserId,mode = "e"})%>" >
                    <img src="../../../Content/images/edit.png" border="0" alt="Edit User" title="Edit User" /></a>

               <%-- <%: Html.ActionLink("Edit User", "ViewUser", "UserAdministration",new{userId=item.UserId,mode="e"},null) %>--%>
                
                <%--  <%: Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ })%>
                |--%>
                <%if (item.username != User.Identity.Name)
                  { %>
                   <a href="<%= Url.Action("DeactivateUser", "UserAdministration", new{userName = item.username,mode = "d", role=ViewData["roleName"]})%>" onclick="return confirm('Are you sure you want to delete this User?')">
                    <img src="../../../Content/images/delete.png" border="0" alt="Delete User" title="Delete User" /></a>
                    
<%--
                <%: Html.ActionLink("Delete User", "DeactivateUser", "UserAdministration", new { userName = item.username, mode = "d", role = ViewData["roleName"] }, new { onclick="javascript:return confirm('Are you sure?');"})%>--%>
                <%--  <%: Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })%>--%> 
                  <a href="<%= Url.Action("ResetPassword", "UserAdministration", new{userName = item.username, role=ViewData["roleName"]})%>" onclick="return confirm('Are you sure you want to reset the password of this User?')">
                    <img src="../../../Content/images/resetPassword.png" border="0" alt="Reset Password" title="Reset Password" /></a>
           <%} %> 
        </div>
           </td>
            <%} %>
        </tr>
        <% } %>
    </table>
    <br />
    <div id="pager">
        <%= Html.Pager((IPagination)(Model as IEnumerable<SLIC.Models.UserAdministration.UserDataModel>))%>
    </div>
    <%--   <p>
        <%: Html.ActionLink("Create User", "ViewUser", "UserAdministration",new{roleName= ViewData["roleName"] },null) %>
    </p>--%>
    <br />
    <div class="buttons">
        <%if (ViewData["isLockedUserPage"] == null || !Convert.ToBoolean(ViewData["isLockedUserPage"]))
          {%>
        <%-- <input type="submit" value='<%= ((isEdit) ? "Update User":"Add User") %>' class="button" />--%>
        <%--  <input type="submit" value="Create"  class="button" />--%>
        <input type="submit" onclick="parent.location='<%: Url.Action("ViewUser", "UserAdministration",new{roleName=ViewData["roleName"],mode="n"}) %>';return false;"
            value="Create User" class="button" />
        <%}
          else if (ViewData["isLockedUserPage"] != null && Convert.ToBoolean(ViewData["isLockedUserPage"]))
          { %>
        <input type="submit" value="Unlock" class="button" onclick="return confirm('Are you sure you want to unlock these users?')" />
        <%} %></div>
    <%} %>
    <%} %>
</asp:Content>
